import functools

from flask import session, g


def do_index_class(index):
    """自定义过滤器,过滤点击排序的class"""

    if index == 1:
        return "first"
    elif index == 2:
        return "second"
    elif index == 3:
        return "third"
    else:
        return ""


# 定义一个用户登录状态装饰器
def user_login_data(func):
    @functools.wraps(func)
    def inner_func(*args, **kwargs):
        user_id = session.get("user_id")
        user = None
        if user_id:
            from info.models import User
            user = User.query.get(user_id)
        g.user = user
        return func(*args, **kwargs)

    return inner_func
